<template>
	<view>
		<view class="page-box">
			<view class="user">
				<view>{{orderInfo.user.name}} {{orderInfo.user.phone}}</view>
				<view>{{address}}</view>
			</view>
			<view class="order">
				<view class="top">
					<view class="left">
						<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
						<view class="store">{{ orderInfo.order_no }}</view>
						<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
					</view>
					<view class="right">{{ status[orderInfo.status-1] }}</view>
				</view>
				<view class="item" v-for="(goods, gindex) in orderInfo.goods.data" :key="gindex">
					<view class="left">
						<image :src="goods.cover_url" mode="aspectFill"></image>
					</view>
					<view class="content">
						<view class="title u-line-2">{{ goods.title }}</view>
						<view class="type">{{ goods.description }}</view>
						<view class="delivery-time">订单：{{ goods.updated_at }}</view>
					</view>

					<view class="right">
						<view class="price">
							{{orderInfo.orderDetails.data[gindex].price}}
						</view>
						<view class="number">x{{ orderInfo.orderDetails.data[gindex].num }}</view>
					</view>
				</view>
				<view class="total">
					共{{ totalNum(orderInfo.orderDetails.data) }}件商品 合计:
					<text class="total-price">
						<!-- ￥{{ priceInt(totalPrice(item.orderDetails.data)) }}.
						<text class="decimal">{{ priceDecimal(totalPrice(item.orderDetails.data)) }}</text> -->
						{{orderInfo.amount}}
					</text>
				</view>
				<!-- <view class="bottom">
					<view class="more"><u-icon name="more-dot-fill" color="rgb(203,203,203)"></u-icon></view>
					<view class="logistics btn">查看物流</view>
					<view class="exchange btn">卖了换钱</view>
					<view class="evaluate btn">{{ pay[item.status-1] }}</view>
				</view> -->
			</view>
			<view class="express">
				<view>订单编号：{{orderInfo.order_no}}</view>
				<view>下单时间：{{orderInfo.pay_time}}</view>
				<view>快递类型：{{orderInfo.express_type}}</view>
				<view>快递单号：{{orderInfo.express_no}}</view>
			</view>
		</view>
		<view class="toPay" @tap="toPay(0)">
			<view class="pay">
				立即付款
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId: null,
				orderInfo:[],
				status:[
					'未支付','已付款','已发货','已完成','已过期'  //  去付款 ， '' ,  确认收货 ， 立即评价 ， ’‘
				], //订单状态
				pay:[
					'去付款','','确认收货','立即评价',''  //  去付款 ， '' ,  确认收货 ， 立即评价 ， ’‘
				], //订单状态
				address:null, //快递地址
			}
		},
		onLoad(option) {
			this.orderId = option.order;
			this.getOrderInfo();
		},
		methods: {
			// 页面数据
			async getOrderInfo() {
				const params = {
					include:'goods,user,orderDetails'
				};
				const res = await this.$u.api.orderInfo(this.orderId,params);
				this.orderInfo = res;
				// 地址
				const addressInfo = await this.$u.api.addressDetail(res.address_id);
				this.address = addressInfo.province + addressInfo.city + addressInfo.county + addressInfo.address ;
				//console.log(res);
				// this.orderList = res.data;
			},
			// 总件数
			totalNum(item) {
				let num = 0;
				item.map(val => {
					num += val.num;
				});
				return num;
			},
			// 去付款
			toPay(id) {
				this.$u.route({
					url: 'pages/order/pay',
					params: {
						order: id
					}
				})
			},
		}
	}
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.user,.express{
		width: 710rpx;
		margin: 20rpx auto;
		border-radius: 20rpx;
		background: #FFFFFF;
		padding: 20rpx;
		view{
			padding: 10rpx;
			
		}
	}

	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}
	}
	.toPay {
		display: flex;
		justify-content: space-around;
		width: 600rpx;
		line-height: 100rpx;
		position: absolute;
		bottom: 30rpx;
		left: 80rpx;
		background-color: red;
		border-radius: 60rpx;
		font-size: 30rpx;
	
		.pay {
			display: flex;
			align-items: center;
			color: #ffffff;
		}
	}
</style>
